Reinventing Haskell Backtracking
نویسنده
چکیده
Almost ten years ago, Ralf Hinze has written a functional pearl on how to derive backtracking functionality for the purely functional programming language Haskell. In these notes, we show how to arrive at the efficient, two-continuation based backtracking monad derived by Hinze starting from an intuitive inefficient implementation that we subsequently refine using well known program transformations. It turns out that the technique can be used to build monads for non-determinism from modular, independent parts which gives rise to various new implementations. Specifically, we show how the presented approach can be applied to obtain new implementations of breadth-first search and iterative deepening depth-first search.
منابع مشابه
Backtracking, Interleaving, and Terminating Monad Transformers
We design and implement a library for adding backtracking computations to any Haskell monad. Inspired by logic programming, our library provides, in addition to the operations required by the MonadPlus interface, constructs for fair disjunctions, fair conjunctions, conditionals, pruning, and an expressive top-level interface. Implementing these additional constructs is easy in models of backtra...
متن کاملMonad Transformers for Backtracking Search
This paper extends Escardó and Oliva’s selection monad to the selection monad transformer, a general monadic framework for expressing backtracking search algorithms in Haskell. The use of the closely related continuation monad transformer for similar purposes is also discussed, including an implementation of a DPLL-like SAT solver with no explicit recursion. Continuing a line of work exploring ...
متن کاملEilenberg-Moore Monoids and Backtracking Monad Transformers
We develop an algebraic underpinning of backtracking monad transformers in the general setting of monoidal categories. As our main technical device, we introduce Eilenberg–Moore monoids, which combine monoids with algebras for strong monads. We show that Eilenberg–Moore monoids coincide with algebras for the list monad transformer (‘done right’) known from Haskell libraries. From this, we obtai...
متن کاملFair Constraint Merging Tableaux in Lazy Functional Programming Style
Constraint merging tableaux maintain a system of all closing substitutions of all subtableau up to a certain depth, which is incrementally increased. This avoids backtracking as necessary in destructive first order free variable tableaux. The first successful implementation of this paradigm was given in an object-oriented style. We analyse the reasons why lazy functional implementations so far ...
متن کاملMonad-Based Logics for Computational Effects
The presence of computational effects, such as state, store, exceptions, input, output, non-determinism, backtracking etc., complicates the reasoning about programs. In particular, usually for each effect (or each combination of these), an own logic needs to be designed. Monads are a well-known tool from category theory that originally has been invented for studying algebraic structures. Monads...
متن کامل